//
//  PxPwdModifyViewController.m
//  OilCard
//
//  Created by Xu Yefeng on 14-5-18.
//  Copyright (c) 2014年 Free. All rights reserved.
//

#import "PxUserInfoViewController.h"
#import <objc/runtime.h>

@implementation PxUserInfoViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyBoardHide) name:UIKeyboardWillHideNotification object:nil];
    }
    return self;
}

- (void)keyBoardHide
{
    [self.contentView setContentOffset:CGPointMake(0, 0) animated:YES];
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self setLogoTitleViewWithTitle:@"个人信息"];
    self.contentView = [[UIScrollView alloc] initWithFrame:self.view.bounds];
    [self.view addSubview:self.contentView];
}

-(void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
    [self setup];
}

-(void)setup
{
    PxUserInfoBean *bean = [PxNetSession sharedSession].currentUser;
    CGFloat top = 0;
    
    LLYTTextField *textfield = [PxWidgetCreater getTextField:@"姓名" andPlacehoder:@"请输入姓名"];
    textfield.width = CGRectGetWidth(self.view.frame) - 30;
    textfield.clearButtonMode = UITextFieldViewModeWhileEditing;
    textfield.text = bean.name;
    self.realName = textfield;
    textfield.top = top;
    [self.contentView addSubview:textfield];
    textfield.delegate = self;
    
    UIView *lineview = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.width, 1)];
    [self.contentView addSubview:lineview];
    lineview.top = textfield.bottom-1;
    lineview.backgroundColor = [UIColor colorWithHTMLStr:@"cacaca"];
    
    top = textfield.bottom;
    
    textfield = [PxWidgetCreater getTextField:@"电话" andPlacehoder:@"请输入电话号码"];
    textfield.width = CGRectGetWidth(self.view.frame) - 30;
    self.phone = textfield;
    textfield.clearButtonMode = UITextFieldViewModeWhileEditing;
    textfield.text = bean.phone;
    textfield.top = top;
    [self.contentView addSubview:textfield];
    textfield.delegate = self;
    [self.phone linkPreField:self.realName];
    
    lineview = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.width, 1)];
    [self.contentView addSubview:lineview];
    lineview.top = textfield.bottom-1;
    lineview.backgroundColor = [UIColor colorWithHTMLStr:@"cacaca"];
    
//    top = textfield.bottom;
//    
//    textfield = [self getTextField:@"邮箱" andPlacehoder:@"请输入邮箱"];
//    self.email = textfield;
//    textfield.clearButtonMode = UITextFieldViewModeWhileEditing;
//    textfield.text = bean.email;
//    textfield.top = top;
//    [self.contentView addSubview:textfield];
//    textfield.delegate = self;
//    [self.email linkPreField:self.phone];
//    
//    lineview = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.width, 1)];
//    [self.contentView addSubview:lineview];
//    lineview.top = textfield.bottom-1;
//    lineview.backgroundColor = [UIColor colorWithHTMLStr:@"cacaca"];
//    
//    top = textfield.bottom;
//    
//    textfield = [self getTextField:@"单位" andPlacehoder:@"请输入单位地址"];
//    self.unit = textfield;
//    textfield.text = bean.company;
//    textfield.top = top;
//    [self.contentView addSubview:textfield];
//    textfield.delegate = self;
//    [self.unit linkPreField:self.email];
//    
//    lineview = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.width, 1)];
//    [self.contentView addSubview:lineview];
//    lineview.top = textfield.bottom-1;
//    lineview.backgroundColor = [UIColor colorWithHTMLStr:@"cacaca"];
}

- (void)didSelectIndex:(NSString *)province andCity:(NSString *)city andTown:(NSString *)town
{
    self.province = province;
    self.city = city;
    self.country = town;
}

- (void)gotoModifyPWD
{
    [self pushViewController:@"PxPwdModifyViewController" withIncomingParam:nil];
}

- (BOOL)passwordCheck
{
    NSString *password = [self.newpwdInput.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
    
    NSString *passwordCfm = [self.newpwdCfmInput.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
    
    if ([password isEqualToString:passwordCfm]) {
        return YES;
    }
    
    //    [self showMSG:@"两次输入的密码不匹配" withType:0];
    [LLAlertService sysAlertWithTip:@"两次输入的密码不匹配" withTitle:@"提示"];
    
    return NO;
}

-(void)hideKeyBoard
{
    [self.view endEditing:YES];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)dealloc
{
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}
@end
